package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {


    @Autowired
    private BaseTrademarkService baseTrademarkService;
    // /admin/product/baseTrademark/{page}/{limit}
    // 品牌管理分类列表
    @GetMapping("{page}/{limit}")
    public Result selectTradeMarkList(@PathVariable Long page,@PathVariable Long limit){

        Page<BaseTrademark> trademarkPage = new Page<>(page, limit);

        IPage<BaseTrademark> page1 = baseTrademarkService.selectTradeMarkList(trademarkPage);

        return Result.ok(page1);
    }

    // 删除品牌信息
    // /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){

        baseTrademarkService.removeById(id);

        return Result.ok();
    }

    // 新增品牌信息
    // /admin/product/baseTrademark/save
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.save(baseTrademark);

        return Result.ok();
    }

    // 修改品牌信息
    // /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);

        return Result.ok();
    }

    // 回显  根据品牌id获取数据
    // /admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result selectById(@PathVariable Long id){
        BaseTrademark ba = baseTrademarkService.getById(id);

        return Result.ok(ba);
    }

}
